﻿
@{
    Layout = "~/Views/Shared/_LayuiLayout.cshtml";
}
<form class="layui-form layui-form-pane">
    <input type="hidden" name="Id" value="@Model.Id" />
    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" autocomplete="off" placeholder="请输入角色名"
                   name="RoleName" value="@Model.RoleName" lay-verify="required" required>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色编号</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" autocomplete="off" placeholder="请输入角色编号"
                   name="RoleCode" value="@Model.RoleCode" lay-verify="required" required>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色级别</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" autocomplete="off"
                   name="RoleLevel" value="@Model.RoleLevel" lay-verify="required" required />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">角色说明</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" placeholder="请输入角色说明" name="RoleExplain">@Model.RoleExplain</textarea>
        </div>
    </div>
    <div class="layui-form-item " align="center">
        <button type="button" class="layui-btn" lay-submit="" lay-filter="Save">保存</button>
        <button type="button" class="layui-btn layui-btn-primary" id="btnCancel">取消</button>
    </div>
</form>
@section scripts{
    <script type="text/javascript">
        var $, layer;
        layui.use(['form'], function () {
            var form = layui.form;
            $ = layui.jquery;
            layer = parent.layer === undefined ? layui.layer : parent.layer;

            // 监听关闭
            $('#btnCancel').on('click', function () {
                layer_close();
            });

            // 监听提交
            form.on('submit(Save)', function (data) {
                var loading = layer.load();
                $.post('@Url.Action("AddOrEdit", "Role")', data.field,
                    function (result) {
                        layer.close(loading);
                        if (result.Success) {
                            layer.msg(result.Message, { icon: 1, time: 2000 });
                            parent.reload();
                            layer_close();
                        } else {
                            layer.alert(result.Message, { icon: 2 });
                        }
                    });
                return false;
            })


        });
    </script>
}

